#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>

#include <sys/mman.h>



void lcd_display_bmp(int x0, int y0, char *bmpfile)
{
	int fd;

	fd = open(bmpfile, O_RDONLY);
	if (fd == -1)
	{
		printf("failed to open bmp file %s\n");
		return ;
	}

	//文件头内容不要，先定位光标54字节处
	lseek(fd, 54, SEEK_SET);

	int i = 0;
	unsigned char pixel[80*80*3];

	read(fd, pixel, 80*80*3);


	//解析并显示 !!!!
	//从下至上，从左至右，保存每一个像素点的  b g r 
	unsigned char b ,g ,r;
	int color;
	int x, y;

	for (y = 0; y < 80; y++)
	{
		for (x = 0; x < 80; x++)
		{
			b = pixel[i++];
			g = pixel[i++];
			r = pixel[i++];

			// r g b 
			color = (r << 16) | (g << 8) | (b);
			lcd_draw_point(x0 + x , y0 + 79  -y, color);
		}
	}




	close(fd);
}
